﻿/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
**/

package com.chasekernan.hxnova.componenteditor;

import org.aswing.JButton;
import org.aswing.JFrame;
import org.aswing.JPanel;
import org.aswing.JScrollPane;
import org.aswing.JTextArea;
import org.aswing.SoftBox;
import org.aswing.SoftBoxLayout;
import flash.events.Event;
import org.aswing.geom.IntDimension;
import org.aswing.border.EmptyBorder;
import org.aswing.Insets;

class DescriptionWindow extends JFrame {

	public static var OK = "ok";
    public static var CANCEL = "cancel";
    
    private var descriptionBox : JTextArea;
    private var okButton : JButton;
    private var cancelButton : JButton;
    
    public function new(?parent : Dynamic) {
        super(parent, "Edit Description", true);
        
        setContentPane(setupContents());
        pack();
        
        okButton.addActionListener(onOK);
        cancelButton.addActionListener(onCancel);
    }
    
    private function setupContents() : JPanel {
        var contents : JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 5));
        contents.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
        
		descriptionBox = new JTextArea();
		descriptionBox.setMaxChars(1000);
		descriptionBox.setWordWrap(true);
		var scrollPane : JScrollPane = new JScrollPane(descriptionBox);
		scrollPane.setPreferredSize(new IntDimension(300, 250));
		contents.append(scrollPane);
		
		var buttonPanel = new JPanel();
        okButton = new JButton("OK");
        buttonPanel.append(okButton);
        cancelButton = new JButton("Cancel");
        buttonPanel.append(cancelButton);
        contents.append(buttonPanel);
		
        return contents;
    }
    
    public function getDescription() : String {
        return descriptionBox.getText();
    }
    
    public function setDescription(description : String) {
        descriptionBox.setText(description);
    }
    
    private function onOK(?e : Dynamic) {
        dispatchEvent(new Event(OK));
    }
    
    private function onCancel(?e : Dynamic) {
        dispatchEvent(new Event(CANCEL));
    }
	
}